<!-- 天气预报 -->
<template>
  <div class="wrap">
    <div class="search_from">
      <div class="logo">
        <img :src="require('@/assets/logo.png')" alt="logo"/>
      </div>
      <div class="form_group">
        <input
        type="text"
        v-model="city"
        @keyup.enter="searchWeather"
        class="input_txt"
        placeholder="请输入查询的天气"
        />
        <button class="input_sub" @click="searchWeather">
          搜 索
        </button>
      </div>
      <div class = hotkey>
        <a href="javascript:;" @click="selectCity('北京')">北京</a>
        <a href="javascript:;" @click="selectCity('上海')">上海</a>
        <a href="javascript:;" @click="selectCity('广州')">广州</a>
        <a href="javascript:;" @click="selectCity('深圳')">深圳</a>
      </div>
    </div>
    <ul class="weather_list">
      <li v-for="(item,index) in WeatherList" :key="index">
        <div class="info_type">
          <span class="iconfont">{{item.type}}</span>
        </div>
        <div class="info_temp">
          <b>{{item.low}}</b>
          ~
          <b>{{item.high}}</b>
        </div>
        <div class="info_data">
          <span>{{item.date}}</span>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name:'WeatherApp',
  data(){
    return{
      city:'',
      WeatherList:[]
    }
  },
  methods:{
    searchWeather(){
      if(!this.city.trim()) return;
      this.WeatherList = [
        { type: '晴', low: '20℃', high: '28℃', date: '今天' },
        { type: '多云', low: '18℃', high: '26℃', date: '明天' },
        { type: '小雨', low: '16℃', high: '24℃', date: '后天' }
      ];
    },
    selectCity(city){
      this.city = city;
      this.searchWeather()
    }
  },
  mounted() {this.selectCity('北京');
  }
}
</script >

<style >
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.wrap{
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Microsoft YaHei',sans-serif;
}
.search_from{
  text-align: center;
  margin-bottom: 30px;
}
.logo img{
  height: 100px;
  margin-bottom: 20px;
}
.form_group{
  display: flex;
  justify-content: center;
  margin-bottom: 15px;
}
.input_txt{
  width: 300px;
  height: 40px;
  padding: 0 15px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
  font-size: 16px;
  outline: none;
}
.input_sub{
  width: 80px;
  height: 40px;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.3s;
}
.input_sub:hover{
  background: #2980b9;
}
.hotkey{
  margin-top: 10px;
}
.hotkey a{
  color: #666;
  margin: 0 10px;
  text-decoration: none;
  font-size: 14px;
}
.hotkey a:hover{
  color: #3498db;
}
.weather_list{
  display: flex;
  justify-content: space-between;
  list-style: none;
}
.weather_list li{
  flex: 1;
  text-align: center;
  padding: 20px;
  background: #f9f9f9;
  border-radius: 8px;
  margin: 0 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.info_type{
  font-size: 24px;
  margin-bottom: 10px;
}
.info_temp{
  font-size: 18px;
  margin-bottom: 10px;
  color: #333;
}
.info_temp b {
  color: #e74c3c;
}

.info_date {
  color: #666;
  font-size: 14px;
}
</style>

